package br.com.sadim.hospital;

import java.io.Serializable;
import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@FacesConverter(forClass=Consulta.class)
public class ConsultaConverter implements Converter {
	private ConsultaRN consultaRN = new ConsultaRN();
	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String string) {
		if(string == null || string.isEmpty()){
			return null;
		}
		return consultaRN.getById(Integer.valueOf(string));
	}
 
	@Override
	public String getAsString(FacesContext context, UIComponent component, Object object) {
		Consulta consulta = (Consulta) object;
		if(consulta == null || consulta.getIdConsulta() == null){
			return null;
		}
		return String.valueOf(consulta.getIdConsulta());
	}
}